package cps_tree_package;

import common.TransactionInteger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author cogs
 */
public class Tree {
    
    private OrdinaryNode root;
    private OrdinaryNode actu;
    
    public Tree(){
        this.root = null;
    }
    
    public Tree(OrdinaryNode root){
        this.root = root;
    }
    
    public void insertTransaction(TransactionInteger transact){       
        this.actu = root;
        
        int pos = 0;
        boolean node_exist;
        
        for(int i = 0; i < transact.getItems().size(); i++){
            
            node_exist = false;
            
            //sprawdzamy czy element nie istnieje juz wsrod dzieci
            for(int j = 0; j < actu.child.size(); j++){
                if(transact.getItems().get(i) == actu.getChild(j).value){
                    pos = j;
                    node_exist = true;
                }
            }

            if(node_exist){     //spr. czy korzeń posiada już taki element
                actu = actu.getChild(pos);
                actu.supp++;
            }
            else{
                actu = actu.addChild(transact.getItems().get(i));
                actu.supp = 1;
            }
        }
        //root.addChild(value)
    }
}
